home *** CD-ROM | disk | FTP | other *** search
- //: C24:Voidrtti.cpp
- // From Thinking in C++, 2nd Edition
- // Available at http://www.BruceEckel.com
- // (c) Bruce Eckel 1999
- // Copyright notice in Copyright.txt
- // RTTI & void pointers
- #include <iostream>
- #include <typeinfo>
- using namespace std;
-
- class Stimpy {
- public:
- virtual void happy() {}
- virtual void joy() {}
- virtual ~Stimpy() {}
- };
-
- int main() {
- void* v = new Stimpy;
- // Error:
- //! Stimpy* s = dynamic_cast<Stimpy*>(v);
- // Error:
- //! cout << typeid(*v).name() << endl;
- } ///:~
-